<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/dropzone/dropzone.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="row">
            <div class="panel">
                <div class="panel-heading">
                    <h3 class="panel-title">企业基本信息</h3>
                </div>
                <div class="panel-body">
                    <div class="col-lg-6">
                        <p>请上传营业执照，系统会自动识别相关信息，如有区别请修改</p>
                        <div class="bord-top pad-ver">
                            <span class="btn btn-success fileinput-button dz-clickable">
					                <i class="fa fa-plus"></i>
					                <span>选择文件</span>
					            </span>

                            <div class="btn-group pull-right">
                                <button id="dz-upload-btn" class="btn btn-primary" type="submit" disabled>
                                    <i class="fa fa-upload-cloud"></i> 上传
                                </button>
                                <button id="dz-remove-btn" class="btn btn-danger cancel" type="reset" disabled>
                                    <i class="demo-psi-trash"></i>
                                </button>
                            </div>
                        </div>
                        <div id="dz-previews">
                            <div id="dz-template" class="pad-top bord-top">
                                <div class="media">
                                    <div class="media-body">
                                        <!--This is used as the file preview template-->
                                        <div class="media-block">
                                            <div class="media-left">
                                                <img class="dz-img" data-dz-thumbnail>
                                            </div>
                                            <div class="media-body">
                                                <p class="text-main text-bold mar-no text-overflow" data-dz-name></p>
                                                <span class="dz-error text-danger text-sm" data-dz-errormessage></span>
                                                <p class="text-sm" data-dz-size></p>
                                                <div id="dz-total-progress" style="opacity:0">
                                                    <div class="progress progress-xs active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0">
                                                        <div class="progress-bar progress-bar-success" style="width:0%;" data-dz-uploadprogress></div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="media-right">
                                        <button data-dz-remove class="btn btn-xs btn-danger dz-cancel"><i class="demo-psi-trash"></i></button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-6">
                        <form class="panel-body form-horizontal form-padding">
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-text-input">单位名称</label>
                            <div class="col-md-9">
                                <input type="text" id="companyName" name="companyName" value="${(companyInfo.name)!}" class="form-control" placeholder="">
                                <small class="help-block" id="name_err" style="display: none">请填入单位名称</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">社会信用代码</label>
                            <div class="col-md-9">
                                <input type="text" id="creditCode" name="creditCode" value="${(companyInfo.creditCode)!}" class="form-control" placeholder="">
                                <small class="help-block" id="creditCode_err" style="display: none">请输入社会信用代码</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">法定代表人</label>
                            <div class="col-md-9">
                                <input type="text" id="operName" name="operName" value="${(companyInfo.operName)!}" class="form-control" placeholder="">
                                <small class="help-block" id="operName_err" style="display: none">请输入法定代表人姓名</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">注册地址</label>
                            <div class="col-md-9">
                                <input type="text" id="address" name="address" value="${(companyInfo.address)!}" class="form-control" placeholder="">
                                <small class="help-block" id="address_err" style="display: none">请输入注册地址</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">用电地址</label>
                            <div class="col-md-9">
                                <input type="text" id="elecFor" name="elecFor" value="${(companyInfo.elecFor)!}" class="form-control" placeholder="">
                                <span onclick="copyAddress()">同注册地址</span>
                                <small class="help-block" id="elecFor_err" style="display: none">请输入用电地址</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">联系人</label>
                            <div class="col-md-9">
                                <input type="text" id="contractName" name="contractName" value="${(companyInfo.contractName)!}" class="form-control" placeholder="">
                                <small class="help-block" id="contractName_err" style="display: none">请输入联系人姓名</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">联系人电话</label>
                            <div class="col-md-9">
                                <input type="text" id="contractPhone" name="contractPhone" value="${(companyInfo.contractPhone)!}" class="form-control" placeholder="">
                                <small class="help-block" id="contractPhone_err" style="display: none">请输入联系人电话</small>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-md-3 control-label" for="demo-email-input">微信号</label>
                            <div class="col-md-9">
                                <input type="text" id="wxNum" name="wxNum" value="${(companyInfo.wxNum)!}" class="form-control" placeholder="">
                                <span onclick="copyPhone()">同联系电话</span>
                                <small class="help-block" id="wxNum_err" style="display: none">请输入微信号码</small>
                            </div>
                        </div>

                        <div class="panel-footer text-right">
                            <button class="btn btn-success" type="button" onclick="save_info()">提交</button>
                        </div>
                        <input type="hidden" id="capital" name="capital" value="${(companyInfo.capital)!}" />
                        <input type="hidden" id="establishDate" name="establishDate" value="${(companyInfo.establishDate)!}" />
                        <input type="hidden" id="types" name="types" value="${(companyInfo.types)!}" />
                        <input type="hidden" id="validPeriod" name="validPeriod"  value="${(companyInfo.validPeriod)!}" />
                        <input type="hidden" id="imgUrl" name="imgUrl" value="${(companyInfo.licenseImgUrl)!}" />
                        <input type="hidden" id="currentId" name="currentId" value="${(companyInfo.id)!}" />
                        <input type="hidden" id="fromU" name="fromU" value="${from!(0)}" />
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </#if>
    <#if part="modal">
    </#if>

    <#if part="foot_script">
        <script src="<@spring.url "/resources/plugins/dropzone/dropzone.min.js"/>"></script>
        <script src="<@spring.url "/resources/js/form-file-upload.js"/>"></script>
    <script type="text/javascript">
        function save_info() {
            $("#name_err").hide();
            $("#creditCode_err").hide();
            $("#operName_err").hide();
            $("#address_err").hide();
            $("#elecFor_err").hide();
            $("#contractName_err").hide();
            $("#contractPhone_err").hide();
            $("#wxNum_err").hide();
            var companyName = $.trim($("#companyName").val());
            if (companyName == "") {
                $("#name_err").show();
                return false;
            }
            var creditCode = $.trim($("#creditCode").val());
            if (creditCode == "") {
                $("#creditCode_err").show();
                return false;
            }
            var operName = $.trim($("#operName").val());
            if (operName == "") {
                $("#operName_err").show();
                return false;
            }
            var address = $.trim($("#address").val());
            if (address == "") {
                $("#address_err").show();
                return false;
            }
            var elecFor = $.trim($("#elecFor").val());
            if (elecFor == "") {
                $("#elecFor_err").show();
                return false;
            }
            var contractName = $.trim($("#contractName").val());
            if (contractName == "") {
                $("#contractName_err").show();
                return false;
            }
            var contractPhone = $.trim($("#contractPhone").val());
            if (contractPhone == "") {
                $("#contractPhone_err").show();
                return false;
            }
            var wxNum = $.trim($("#wxNum").val());
            if (wxNum == "") {
                $("#wxNum_err").show();
                return false;
            }
            var capital = $("#capital").val();
            var establishDate = $("#establishDate").val();
            var types = $("#types").val();
            var validPeriod = $("#validPeriod").val();
            var imgUrl = $("#imgUrl").val();
            var currentId = $("#currentId").val();
            var fromU = $("#fromU").val();
            $.post("<@spring.url "/companyInfo/update"/>",{
                companyId:currentId, companyName:companyName, creditCode:creditCode, operName:operName, address:address,
                elecFor:elecFor, contractName:contractName, contractPhone:contractPhone, wxNum:wxNum,
                capital:capital, establishDate:establishDate, types:types, validPeriod:validPeriod,
                imgUrl:imgUrl
            }, function (data) {
                if (data.code == 1) {
                    alert("基本信息编辑成功。");
                    if (fromU != "" && fromU == 1){
                        <#if detailInfo??>
                        window.location.href="<@spring.url "/companyInfo/editDetail/${detailInfo.id}/pro"/>";
                        <#else>
                        window.location.href="<@spring.url "/companyInfo/newDetail/"/>"+data.result.id+"/pro";
                        </#if>
                    } else {
                        window.location.reload();
                    }
                } else {
                    alert(data.message);
                }

            });
        }

        function copyAddress() {
            $("#elecFor").val($("#address").val());
        }

        function copyPhone() {
            $("#wxNum").val($("#contractPhone").val());
        }

    </script>
    </#if>
</@t.html>